require(['../config/requireconfig'],function(config){
	//根据需要添加
	require(['jquery','common/pccommons'],function($,com){
		
        com.init({headerPos:{menu:1,sub:2}});
		var pageLogic = new PageLogic($,com);
		pageLogic.init();

	});
});
var PageLogic = function($,com){
	return{
		init:function(){
			var _this = this;
			_this.initData();
		},
		initData:function(){
			var _this = this;
			com.ajax({
				url:"/activity_init.json",
				success:function(res){
					_this.initYear(res.data.years);
				}
			})
		},
		initYear:function(years){
			var _this = this;
			var html = "";
			var first = "";
			$(years).each(function(idx){
				var active ="";
				var info = "";
				if(idx == 0){
					active ="arrow02";
					info = "active";
					first = this;
				}
				html +=' <div class="report-list-item" tg="' + this + '">';
				html +='	  <div class="report-year" tg="' + this + '">' + this + '<i class="arrow01 ' + active + '"></i></div>';
				html +='	  <ul class="report-list-con ' + info + '" >';
				html +='	  </ul>';
				html +=' </div>';
			});
			$(".report-list").html(html);
			$(".report-year").click(function(){
				if($(this).find("i").hasClass("arrow02")){
					$(this).find("i").removeClass("arrow02");
					$(this).next().removeClass("active");
					$(this).next().hide();
				}else{
					$(this).find("i").addClass("arrow02");
					$(this).next().show();
					$(this).next().addClass("active");
					if($(this).next().find("li").length == 0){
						_this.getYearData($(this).attr("tg"),$(this).next());	
					}
				}
			});
			_this.getYearData(first,$(".report-year[tg=" + first + "]").next());
		},
		getYearData:function(year,con){
			var _this = this;
			com.ajax({
				url:"/activity_year.json",
				data:{year:year},
				success:function(res){
					if(res.data){
						var html = "";
						$(res.data).each(function(){
							html +='<li tg="' + this.id + '">';
							html +='  <a href="#" style="color: #3c3c3c;display: block;">';
							html +='	<div class="f-left arrow-img">';
							html +='	</div>';
							html +='	<div class="f-right report-list-right-con">';
							html +='		<div class="f-left report-list-right-con-text">';
							html +='		  <p>' + this.reportTimeStr + '</p>';
							html +='		  <p class="remark">' + this.viewTitle + '</p>';
							html +='		  <p>' + this.roundupContext + '</p>';
							html +='		</div>';
							html +='		<div class="f-right">';
							html +='		  <img class="report-list-right-con-img" src="' + (com._Options.domain + this.viewImg) + '">';
							html +='		</div>';
							html +='        <div class="rep-content"></div> '
							html +='	</div>';
							html +='  </a>';
							html +='</li>';
						});
						$(con).html(html);
						$(con).find("li").on("click",function(){
							var liCon = $(this);
							if($(this).hasClass("expand")){
								$(this).removeClass("expand");
								setTimeout(function(){
									_this.setPos(liCon);
								},200);
							}else{
								$(".report-list-item").find("li").removeClass("expand");
								$(this).addClass("expand");
								var tg = $(this).attr("tg")
								com.ajax({
									url:"/activity_detail.json",
									data:{id:tg},
									success:function(res){
										_this.setPos(liCon);
										var obj = liCon.find(".rep-content");
										var html = com.utils().htmldecode(res.data.context);
										liCon.find(".rep-content").html(html);
									}
								});
							}
						});
						$(con).find("li").find(".rep-content").on("click",function(e){
							com.utils().pervent(e);
						})
					}
				}
			})
		},
		setPos:function(liCon){
			var current = liCon.parent().parent().attr("tg");
			var totalHeight = 0;
			$(".report-list-item").each(function(){
				if(current < $(this).attr("tg")){
					totalHeight = totalHeight + $(this).height();
				}
			});
			var position = liCon.position();
			totalHeight += MediaSize.emToPix(10);
			$(window).scrollTop(totalHeight + position.top);
		}

	}
}